package cn.iocoder.yudao.module.wrdk.controller.admin.grid;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.*;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.wrdk.controller.admin.grid.vo.*;
import cn.iocoder.yudao.module.wrdk.dal.dataobject.grid.wrdkgridDO;
import cn.iocoder.yudao.module.wrdk.convert.grid.wrdkgridConvert;
import cn.iocoder.yudao.module.wrdk.service.grid.wrdkgridService;

@Api(tags = "Crazy!!!管理后台 - 地块坐标")
@RestController
@RequestMapping("/wrdk/wrdkgrid")
@Validated
public class wrdkgridController {

    @Resource
    private wrdkgridService wrdkgridService;

    @PostMapping("/create")
    @ApiOperation("创建地块坐标")
    @PreAuthorize("@ss.hasPermission('wrdk:wrdkgrid:create')")
    public CommonResult<Long> createwrdkgrid(@Valid @RequestBody wrdkgridCreateReqVO createReqVO) {
        return success(wrdkgridService.createwrdkgrid(createReqVO));
    }

    @PutMapping("/update")
    @ApiOperation("更新地块坐标")
    @PreAuthorize("@ss.hasPermission('wrdk:wrdkgrid:update')")
    public CommonResult<Boolean> updatewrdkgrid(@Valid @RequestBody wrdkgridUpdateReqVO updateReqVO) {
        wrdkgridService.updatewrdkgrid(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除地块坐标")
    @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class)
    @PreAuthorize("@ss.hasPermission('wrdk:wrdkgrid:delete')")
    public CommonResult<Boolean> deletewrdkgrid(@RequestParam("id") Long id) {
        wrdkgridService.deletewrdkgrid(id);
        return success(true);
    }

    @GetMapping("/get")
    @ApiOperation("获得地块坐标")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
    @PreAuthorize("@ss.hasPermission('wrdk:wrdkgrid:query')")
    public CommonResult<wrdkgridRespVO> getwrdkgrid(@RequestParam("id") Long id) {
        wrdkgridDO wrdkgrid = wrdkgridService.getwrdkgrid(id);
        return success(wrdkgridConvert.INSTANCE.convert(wrdkgrid));
    }

    @GetMapping("/list")
    @ApiOperation("获得地块坐标列表")
    @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
    @PreAuthorize("@ss.hasPermission('wrdk:wrdkgrid:query')")
    public CommonResult<List<wrdkgridRespVO>> getwrdkgridList(@RequestParam("ids") Collection<Long> ids) {
        List<wrdkgridDO> list = wrdkgridService.getwrdkgridList(ids);
        return success(wrdkgridConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @ApiOperation("获得地块坐标分页")
    @PreAuthorize("@ss.hasPermission('wrdk:wrdkgrid:query')")
    public CommonResult<PageResult<wrdkgridRespVO>> getwrdkgridPage(@Valid wrdkgridPageReqVO pageVO) {
        PageResult<wrdkgridDO> pageResult = wrdkgridService.getwrdkgridPage(pageVO);
        return success(wrdkgridConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @ApiOperation("导出地块坐标 Excel")
    @PreAuthorize("@ss.hasPermission('wrdk:wrdkgrid:export')")
    @OperateLog(type = EXPORT)
    public void exportwrdkgridExcel(@Valid wrdkgridExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<wrdkgridDO> list = wrdkgridService.getwrdkgridList(exportReqVO);
        // 导出 Excel
        List<wrdkgridExcelVO> datas = wrdkgridConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "地块坐标.xls", "数据", wrdkgridExcelVO.class, datas);
    }

}
